    /*  
    championBuilder - Champions Online character planner.
    Copyright (C) 2009 Moritz Hartmeier
    
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
    
    You can find the GNU General Public License in the data folder.
    */


package ch.zarzu.champions.builder.gui;

import java.awt.*;

import javax.swing.*;

import ch.zarzu.champions.builder.SystemLink;
import ch.zarzu.util.*;

public class PowerTypeTag extends PowerListItem {
    
    private SpringLayout layout;
    private JLabel label;
    private TitlePhrase name;

    public PowerTypeTag(String n) {
        setName(n);
        if(!n.equals("")) {
            layout = new SpringLayout();
            setLayout(layout);
            
            ImageIcon icon = new ImageIcon(AppPath.get() + "images/misc/tag.png");
            label = new JLabel(icon);
            label.setPreferredSize(new Dimension(icon.getIconWidth() + 2, icon.getIconHeight()));
            
            redraw();
        }
    }
    
    public void redraw() {
        if(!getName().equals("")) {
            removeAll();
            
            name = new TitlePhrase(SystemLink.getInstance().translate(getName()), "medium");
            add(name);
            add(label);
            
            layout.putConstraint(SpringLayout.WEST, name, label.getIcon().getIconWidth()/2 - name.getLength()/2, SpringLayout.WEST, this);
            layout.putConstraint(SpringLayout.NORTH, name, 3, SpringLayout.NORTH, this);
            layout.putConstraint(SpringLayout.WEST, label, 0, SpringLayout.WEST, this);
            layout.putConstraint(SpringLayout.NORTH, label, 0, SpringLayout.NORTH, this);
            layout.putConstraint(SpringLayout.EAST, this, 0, SpringLayout.EAST, label);
            layout.putConstraint(SpringLayout.SOUTH, this, 0, SpringLayout.SOUTH, label);
        }
    }
}
